var canvas = document.getElementById("canvas");
var context = canvas.getContext("2d");
function plane(){
	//穿建飞机
	this.planeImg = new Image;
	this.planeImg.src = "img/herofly.png";
	//创建飞机初始位置
	var PLANEWIDTH = 66;
	var PLANEHEIGHT = 82;
	this.planeX = (canvas.width - PLANEWIDTH)/2;
	this.planeY = canvas.height - PLANEHEIGHT;
	//判断飞机移动方向位置 0代表左，1代表右 2代表上，3代表下
	this.direction = -1;
	this.movePlane = function(moveSpeed){
		switch (this.direction){
			case 0:
				this.planeX -= moveSpeed;
				if(this.planeX <= 0){
					this.planeX = 0;
				}
			case 1:
				this.planeX += moveSpeed;
				if(this.planeX >= canvas.width - PLANEWIDTH){
					this.planeX = canvas.width - PLANEWIDTH;
				}
			case 2:
				this.planeY -= moveSpeed;
				if(this.planeY <= 0){
					this.planeY = 0;
				}
			case 3:
			 	this.planeY += moveSpeed;
			 	if(this.planeY >= canvas.height - PLANEHEIGHT){
			 		this.planeY = canvas.height - PLANEHEIGHT;
			 	}
				break;
			default:
				break;
		}
		this.animatePlane();
		//重新绘制飞机
		this.drawPlane();
	}	
	//飞机图片切换
	//定义一个变量记录飞机每栋一次的状态
	this.cutX = 0;
	this.animatePlane = function(){
		this.cutX++;
		if(this.cutX>1){
			this.cutX = 0;
		}
	}
	//飞机打出子弹（默认单排子弹发出）
	this.bullet = {name:"bullet1",bulletWidth:6,bulletHeight:14};
	//绘制飞机
	this.drawPlane = function(){
		context.beginPath();
		context.drawImage(this.planeImg,this.cutX*PLANEWIDTH,0,PLANEWIDTH,PLANEHEIGHT,this.planeX,this.planeY,PLANEWIDTH,PLANEHEIGHT);
    		context.save(); 
	}
	}	
	
//	document.addEventListener("touchmove",function(event){event.preventDefault()},false);

